package com.mokee.android.ShipPass;

import com.mokee.android.Login.LoginActivity;
import com.mokee.android.SharedPreference.MySharedPreferences;
import com.mokee.android.SharedPreference.MyValuesString;
import com.mokee.android.database.DataBaseHelper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class WelcomeActivity extends Activity {
	
	private RelativeLayout relativeLayout;
	private ImageView iv_WelcomeShip;
	private Handler mHandler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		
		relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout_welcome);
		iv_WelcomeShip = (ImageView) findViewById(R.id.iv_WelcomeShip);
		
		MySharedPreferences.init(this);
		DataBaseHelper.getInstance(getApplicationContext());
	} 
	
	@Override
	protected void onResume() {
		super.onResume();
		mHandler = new Handler();
		mHandler.postDelayed(mWelcomeRunnable, 100);
	}
	
	private Runnable mWelcomeRunnable = new Runnable() {
		
		@Override
		public void run() {
			// int shipWidth = iv_WelcomeShip.getWidth();
			// int shipLeft = iv_WelcomeShip.getLeft();
			// int windowWidth = relativeLayout.getWidth();
			
			AnimationSet set = new AnimationSet(true);
			Animation welcome_Animation = new TranslateAnimation(0, 250, 0, 0);
			welcome_Animation.setDuration(2 * 1000);
			welcome_Animation.setAnimationListener(new AnimationListener() {
				
				@Override
				public void onAnimationStart(Animation animation) {}
				
				@Override
				public void onAnimationRepeat(Animation animation) {}
				
				@Override
				public void onAnimationEnd(Animation animation) {
					//跳转
					Intent jumpIntent;
					if(!MyValuesString.getLoginName().equals("") && !MyValuesString.getLoginPassward().equals("")){
						jumpIntent = new Intent(WelcomeActivity.this, MainActivity.class);
					} else {
						jumpIntent = new Intent(WelcomeActivity.this, LoginActivity.class);
					}
					startActivity(jumpIntent);
					
					finish();
					onDestroy();
				}
			});
			set.addAnimation(welcome_Animation);
			set.setFillAfter(true);
			iv_WelcomeShip.startAnimation(set);
		}
	};
}
